package com.lagou.mapper;

import com.lagou.pojo.Order;
import com.lagou.pojo.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 使用注解的IOrderMapper
 */
//public interface IOrderMapper {
//
//    //查询订单的同时还查询该订单所属的用户
//
//    @Results({
//            @Result(property = "id",column = "id"),
//            @Result(property = "orderTime",column = "orderTime"),
//            @Result(property = "total",column = "total"),
//            @Result(property = "user",column = "uid",javaType = User.class,
//                    one=@One(select = "com.lagou.mapper.IUserMapper.findUserById"))
//    })
//    @Select("select * from orders")
//    public List<Order> findOrderAndUser();
//
//
//    @Select("select * from orders where uid = #{uid}")
//    public List<Order> findOrderByUid(Integer uid);
//
//
//
//
//}

/**
 * 不使用注解的IOrderMapper
 */
public interface IOrderMapper {

    //查询订单的同时还查询该订单所属的用户

//    public List<Order> findOrderAndUser();


    //@Results相当于mapper.xml中的resultMap
    //@Result相当于result
    //@One相当于association
    //@Many相当于collection
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "orderTime", column = "orderTime"),
            @Result(property = "total", column = "total"),
            @Result(property = "user", column = "uid", javaType = User.class,
                    one = @One(select = "com.lagou.mapper.IUserMapper.findUserById"))
    })
    @Select("select * from orders")
    public List<Order> findOrderAndUser();

    @Select("select * from orders where uid = #{uid}")
    public List<Order> findOrderByUid(Integer uid);


}
